﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace WebApplication1.Models
{
    [DependsOn(
        typeof(AbpAspNetCoreMvcModule), //启动MVC模块
        typeof(AbpEntityFrameworkCoreModule) //启动EFCODE模块
        )] 
    public class AppModule:AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            //context.Services.AddAbpDbContext<MyDbContext>(options => { //注入上下文对象
            //options.AddDefaultRepositories(includeAllEntities: true);//自动为DbContext中的实体创建默认仓储,默认是为继承了Entity<Guid>的实体创建仓储，如果其他实体也要创建，必须设置includeAllEntities: true
          

            //}); //配置注入
            //Configure<AbpDbContextOptions>(options => {
            //    options.UseMySQL(); //选择使用mysql数据库
            //});



        }

        
        /// <summary>
        /// 在启动模块初始化中，我们就可以把startup中的配置都搬过来
        /// </summary>
        /// <param name="context"></param>
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }


            app.UseRouting();


            app.UseConfiguredEndpoints();
        }
    }
}
